package com.ruoyi.web.controller.workJob;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.worker.domain.DailySalary;
import com.ruoyi.worker.domain.DailySalaryModifyLog;
import com.ruoyi.worker.domain.DailySalaryTotal;
import com.ruoyi.worker.service.EmployeeSalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salaryApi")
public class EmployeeSalaryController extends BaseController {

    @Autowired
    private EmployeeSalaryService employeeSalaryService;


    //    @PreAuthorize("@ss.hasPermi('job:employeeSalary:query')")
    @GetMapping("/listEmployeeSalary")
    public TableDataInfo listEmployeeSalary(DailySalaryTotal dailySalaryTotal) {
        startPage();
        List<DailySalaryTotal> list = employeeSalaryService.listEmployeeSalary(dailySalaryTotal);
        return getDataTable(list);
    }

    //    @PreAuthorize("@ss.hasPermi('job:employeeSalary:detail:query')")
    @GetMapping("/listEmployeeSalaryDetail")
    public TableDataInfo listEmployeeSalaryDetail(DailySalary dailySalary) {
        startPage();
        List<DailySalary> list = employeeSalaryService.listEmployeeSalaryDetail(dailySalary);
        return getDataTable(list);
    }

    @Log(title = "人员薪资", businessType = BusinessType.EXPORT)
//    @PreAuthorize("@ss.hasPermi('job:employeeSalary:export')")
    @GetMapping("/exportSalaryBills/{salaryDailyTotalIds}")
    public AjaxResult exportSalaryBills(@PathVariable Long[] salaryDailyTotalIds) {
        List<DailySalary> list = employeeSalaryService.listEmployeeSalaryDetail(salaryDailyTotalIds);
        ExcelUtil<DailySalary> util = new ExcelUtil<DailySalary>(DailySalary.class);
        return util.exportExcel(list, "员工薪资表");
    }

    /**
     * @description: 修改临时工工资
     * @author 刘松山
     * @date 2021/12/23 13:46
     */
    @Log(title = "修改临时工工资", businessType = BusinessType.UPDATE)
    @PutMapping("/updateSalary")
    public AjaxResult updateSalary(@Validated @RequestBody DailySalary dailySalary) {
        dailySalary.setCreateBy(getUsername());
        return toAjax(employeeSalaryService.updateSalary(dailySalary));
    }

    /**
     * @description: 临时工修改工资流水
     * @author 刘松山
     * @date 2021/12/23 14:33
     */
    @GetMapping("/listLog")
    public TableDataInfo listLog(DailySalaryModifyLog dilySalaryModifyLog) {
        startPage();
        List<DailySalaryModifyLog> list = employeeSalaryService.listDailySalaryModifyLog(dilySalaryModifyLog);
        return getDataTable(list);
    }
}
